from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)

app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = 'leopoldo.fosy@gmail.com'
app.config['MAIL_PASSWORD'] = 'eexwhbmmujxnfvma'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(app)

app.route('/')
def index():
    try:
        msg = Message('Hello', sender='leopoldo.fosy@gmail.com', recipients=['leopoldo.fosy@gmail.com'])
        msg.body = "Hello, this email was send from Flask"
        mail.send(msg)
        return "Message sent"
    except:
        return "Error en el mail"

if __name__ == '__main__':
    app.run(debug=True)